package com.caltco.cargo.ops.modules.sys.controller;

import com.caltco.cargo.ops.common.api.R2;
import com.caltco.cargo.ops.common.api.Result;
import com.caltco.cargo.ops.modules.sys.entity.UserLevel;
import com.caltco.cargo.ops.modules.sys.request.UpdateLevelRequest;
import com.caltco.cargo.ops.modules.sys.service.LearnWordService;
import com.caltco.cargo.ops.modules.sys.request.LearnWordRequest;
import com.caltco.cargo.ops.modules.sys.vo.UserLevelVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("LearnWordController")
@RequestMapping("/api/learn-word")
public class LearnWordController {
    private final LearnWordService learnWordService;

    public LearnWordController(LearnWordService learnWordService) {
        this.learnWordService = learnWordService;
    }

    @PostMapping("saveWord")
    public Result<String> getWordByType(@RequestBody LearnWordRequest request){
        return learnWordService.getWordByType(request)? R2.ok("新增成功"):R2.err("新增失败");
    }

    @PostMapping("updateLevel")
    public Result<String> updateLevel(@RequestBody UpdateLevelRequest request){
        return learnWordService.updateLevel(request)? R2.ok("更新成功"):R2.err("更新失败");
    }

    @GetMapping("getLevel")
    private Result<UserLevelVO> getLevel(){
        return R2.ok(learnWordService.getLevel());
    }

    @GetMapping("getLeaderboard")
    private Result<List<UserLevelVO>> getLeaderboard(){
        return R2.ok(learnWordService.getLeaderboard());
    }
}
